﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Data;
using Windows.UI.Xaml.Data;

namespace HDK.API.Syndication
{
    /*
    public abstract class PostFilter: DataViewFiltererBase
    {
        public PostFilter(IEnumerable<ISyndicationPost> items) : base(items)
        {
        }
    }
    public abstract class FilteredPostFilter : PostFilter
    {
        // Fields
        private PostFilter _SelectedSubFilter;

        // Methods
        public FilteredPostFilter(IEnumerable<ISyndicationPost> items) : base(items)
        {
            this._SelectedSubFilter = null;
        }

        public override void RefreshResults()
        {
            if (this.SelectedSubFilter != null)
            {
                this.SelectedSubFilter.RefreshResults();
                base.Results = this.SelectedSubFilter.Results;
            }
        }

        public abstract void RefreshSubFilters();

        // Properties
        public PostFilter SelectedSubFilter
        {
            get
            {
                return this._SelectedSubFilter;
            }
            set
            {
                this._SelectedSubFilter = value;
                this.RefreshResults();
                base.RaisePropertyChanged("SelectedSubFilter");
            }
        }

        public abstract List<PostFilter> SubFilters { get; }
    }

    public class SinglePostPropertyFilter : PostFilter
    {
        // Fields
        private Func<ISyndicationPost, string> _PropertySelector;

        // Methods
        public SinglePostPropertyFilter(IEnumerable<ISyndicationPost> library, string name, Func<ISyndicationPost, string> PropertySelector)
            : base(library)
        {
            this.Name = name;
            this._PropertySelector = PropertySelector;
        }

        public override void RefreshResults()
        {
            var collection = base.Items.Where((pcvm) => _PropertySelector(pcvm).Equals(this.Name));
            base.Results = new List<ISyndicationPost>(collection);
        }

        // Properties
        public override string DisplayText
        {
            get
            {
                return this.Name;
            }
        }

        public override bool HasSubFilters
        {
            get
            {
                return false;
            }
        }

        public string Name { get; set; }
    }


    public class AllPostsFilter : PostFilter
    {
        // Methods
        public AllPostsFilter(IEnumerable<ISyndicationPost> library)
            : base(library)
        {
        }

        public override void RefreshResults()
        {
            base.Results = new List<ISyndicationPost>(base.Items.AsEnumerable<ISyndicationPost>());
        }

        // Properties
        public override string DisplayText
        {
            get
            {
                return "All";
            }
        }

        public override bool HasSubFilters
        {
            get
            {
                return false;
            }
        }
    }

    public class PostPropertyFilter : FilteredPostFilter
    {
        // Fields
        private Func<ISyndicationPost, string> _PropertySelector;
        private List<PostFilter> _SubFilters;
        private string _Title;

        // Methods
        public PostPropertyFilter(IEnumerable<ISyndicationPost> library, string Title, Func<ISyndicationPost, string> PropertySelector)
            : base(library)
        {
            this._SubFilters = new List<PostFilter>();
            this._Title = Title;
            this._PropertySelector = PropertySelector;
        }

        public override void RefreshSubFilters()
        {
            //var collection = base.Library.Items;

            //this._SubFilters = new List<ProjectFilter>(collection);
        }

        // Properties
        public override string DisplayText
        {
            get
            {
                return this._Title;
            }
        }

        public override bool HasSubFilters
        {
            get
            {
                return true;
            }
        }

        public override List<PostFilter> SubFilters
        {
            get
            {
                return this._SubFilters;
            }
        }
    }

    public class TitleFilter : PostPropertyFilter
    {
        // Methods
        public TitleFilter(IEnumerable<ISyndicationPost> library)
            : base(library, "Title", (pvm) => (pvm as ISyndicationPost).Title)
        {
        }
    }


    public class FeedFilter : FilteredPostFilter
    {
        // Fields
        private List<PostFilter> _SubFilters;

        // Methods
        public FeedFilter(IEnumerable<ISyndicationPost> library)
            : base(library)
        {
            this._SubFilters = new List<PostFilter>();
            this._SubFilters.Add(new AllPostsFilter(library));
            this._SubFilters.Add(new TitleFilter(library));
            //this._SubFilters.Add(new RecentProjectsFilter(library));
            //this._SubFilters.Add(new PortfolioProjectFilter(library));
            //this._SubFilters.Add(new StakeholdersFilter(library));
            //this._SubFilters.Add(new StatusFilter(library));
            //this._SubFilters.Add(new AuthorsFilter(library));
            //this._SubFilters.Add(new DecadeFilter(library));
            this._SubFilters.Sort((f1, f2) => string.Compare(f1.DisplayText, f2.DisplayText));
        }

        public override void RefreshResults()
        {
            if ((base.Items != null))
            {
                base.Results = new List<ISyndicationPost>(base.Items.AsEnumerable<ISyndicationPost>());
            }
        }

        public override void RefreshSubFilters()
        {
        }

        // Properties
        public override string DisplayText
        {
            get
            {
                return "Projects";
            }
        }

        public override bool HasSubFilters
        {
            get
            {
                return true;
            }
        }

        public override List<PostFilter> SubFilters
        {
            get
            {
                return this._SubFilters;
            }
        }
    }
    */
}
